import os


folder_path = r"C:\Users\cenkai\Desktop\PCB_Detection\svg"
for filename in os.listdir(folder_path):
    if 'h' in filename or "后" in filename:
        file_path = os.path.join(folder_path, filename)
        try:
            os.remove(file_path)
            print(f"已删除: {file_path}")
        except Exception as e:
            print(f"无法删除 {file_path}: {e}")
    if "前" in filename:
        new_filename = filename.replace("前", "q")
        old_path = os.path.join(folder_path, filename)
        new_path = os.path.join(folder_path, new_filename)
        try:
            os.rename(old_path, new_path)
            print(f"已重命名: {filename} -> {new_filename}")
        except Exception as e:
            print(f"无法重命名 {filename}: {e}")